package com.blocks.generator.engine;

import com.blocks.generator.model.TableModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Properties;

/**
 * @author <a href="mailto:idler41@163.com">linfuxin</a> created by 2022-07-01 14:43:23
 */
@Slf4j
public class VelocityGenerator {
    private static final VelocityEngine VE;

    static {
        Properties properties = new Properties();
        properties.setProperty(Velocity.OUTPUT_ENCODING, StandardCharsets.UTF_8.name());
        properties.setProperty(Velocity.INPUT_ENCODING, StandardCharsets.UTF_8.name());
        properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, StringUtils.EMPTY);
        VE = new VelocityEngine(properties);
        VE.init();
    }

    /**
     *
     * @param tableModelList 原始扫描的表-对象 映射模型
     */
    public static void generate(List<TableModel> tableModelList) {
        // 1. 遍历模板

        // 2. 根据模型进行上下文加工 => 插件化执行(包括url动态扫描的plugin)

        // 3. 生成目标文件
    }
}
